<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-form
      :model="formData"
      :rules="rules"
      size="mini"
      labelPosition="right"
      labelWidth="80px"
      ref="form"
    >
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane
            class="l-tabs-container"
            :label="$t('主表信息')"
            name="tab0"
          >
            <el-row :gutter="0">
              <div class="l-rblock">
                <el-col :span="24">
                  <el-form-item
                    :label="$t('授权角色')"
                    prop="lr_base_file_auth_f_ObjId"
                  >
                    <l-role-select
                      v-model="formData.lr_base_file_auth_f_ObjId"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item
                    :label="$t('授权类型')"
                    prop="lr_base_file_auth_f_AuthType"
                  >
                    <l-select
                      :multiple="true"
                      :options="lr_base_file_auth_f_AuthTypeOptions"
                      v-model="formData.lr_base_file_auth_f_AuthType"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item
                    :label="$t('到期日期')"
                    prop="lr_base_file_auth_f_Time"
                  >
                    <l-date
                      :readonly="false"
                      format="yyyy-MM-dd"
                      dateType="date"
                      :clearable="true"
                      v-model="formData.lr_base_file_auth_f_Time"
                      :placeholder="$t('please select')"
                    />
                  </el-form-item>
                </el-col>
                <el-col v-if="isFolder == 1" :span="24">
                  <el-form-item
                    labelWidth="96px"
                    :label="$t('作用子File 夹')"
                    prop="lr_base_file_auth_f_IsChild"
                  >
                    <el-switch
                      :active-value="1"
                      :inactive-value="0"
                      v-model="formData.lr_base_file_auth_f_IsChild"
                    >
                    </el-switch>
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.system.file;

export default {
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
    fileInfoId: String,
    isFolder: Number,
  },
  data() {
    return {
      moduleCode: "demo_xx",
      activeName: "tab0",
      formData: {
        lr_base_file_auth_f_ObjId: "", // 授权角色
        lr_base_file_auth_f_AuthType: "", // 授权类型
        lr_base_file_auth_f_Time: "", // 到期日期
        lr_base_file_auth_f_IsChild: 1, // 到期日期
      },
      rules: {
        lr_base_file_auth_f_ObjId: [{ required: true, message: this.$t("please select") }],
        lr_base_file_auth_f_AuthType: [{ required: true, message: this.$t("please select") }],
      },
    };
  },
  computed: {
    lr_base_file_auth_f_AuthTypeOptions() {
      const res = [
        { label: this.$t("查看"), value: "01" },
        { label: this.$t("上传"), value: "02" },
        { label: this.$t("下载"), value: "03" },
        { label: this.$t("移动"), value: "04" },
        { label: this.$t("Delete"), value: "05" },
        { label: this.$t("还原"), value: "06" },
        { label: this.$t("授权"), value: "07" },
        { label: this.$t("重命名"), value: "08" },
        { label: this.$t("彻底Delete"), value: "09" },
      ];
      if (this.isFolder == 1) {
        res.push(
          ...[
            { label: this.$t("File 夹Add"), value: "10" },
            { label: this.$t("File 夹Delete"), value: "11" },
            { label: this.$t("File 夹移动"), value: "12" },
            { label: this.$t("File 夹授权"), value: "13" },
            { label: this.$t("File 夹上传"), value: "14" },
            { label: this.$t("File 夹重命名"), value: "15" },
          ]
        );
      }

      return res;
    },
  },
  methods: {
    // Reset表单
    resetForm() {
      this.$formClear(this.$refs.form);
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }

      return true;
    },
    // 设置表单数据
    setForm(data) {
      this.$setFormData(this.formData, data, "lr_base_file_auth");
    },
    // 获取表单数据
    getForm() {
      return this.$getFormData(this.formData, "lr_base_file_auth");
    },

    async saveForm({ keyValue, isEdit }) {
      const postData = this.getForm();
      postData.f_FileInfoId = this.fileInfoId;
      postData.f_IsFolder = this.isFolder;
      postData.f_ObjType = 2;
      if (isEdit) {
        // Edit
        return await this.$awaitWraper(api.updateAuth(keyValue, postData));
      } else {
        // Add
        return await this.$awaitWraper(api.addAuth(postData));
      }
    },
  },
};
</script>